<?php
/**
 * Created by PhpStorm.
 * User: wangjiangtao
 * Date: 2021/11/6
 * Time: 17:50
 */

namespace App\Console\Commands;

use App\Model\Number;
use App\Model\UserUuidLiangLog;
use Illuminate\Console\Command;

class UserUUidLiangCheckCommand extends Command
{

    private $prev = [];
    private $model = null;
    private $numbertable = null;
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'UserUUidLiangCheckCommand';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '检测靓号状态';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct(UserUuidLiangLog $userUuidLiangLog,Number $number)
    {
        parent::__construct();
        $this->model = $userUuidLiangLog;
        $this->numbertable = $number;
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        set_time_limit(0);
        $end_date = date('Y-m-d H:i:s',strtotime('+10 year',time()));
        $data = $this->model->where('status',1)->where('end_at','<',time())->get();
        foreach ($data as $item){
            $user = $this->model->where('user_id',$item->user_id)->first();
            $res = $this->numbertable->setUUID($item->user_id,$user->old_uuid);
            if ($res['code'] == 0) {
                $this->model->updateUidStatus($item->user_id);
                $this->model->setUidLog('', $item->user_id, $item->new_uuid, $user->old_uuid, $end_date, 1);
            }
            continue;
        }
    }
}
